package edu.cebanc.spring.biblioteca.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import edu.cebanc.spring.biblioteca.domain.Autor;

@Repository("autoresDAO")
public class AutoresDAOImpl implements AutoresDAO {

	@Autowired
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Autor> getAutores() {
		// TODO Auto-generated method stub
		return (List<Autor>)sessionFactory.getCurrentSession().createCriteria(Autor.class).list();
	}

	@Override
	public Autor getAutor(int id) {
		// TODO Auto-generated method stub
		return (Autor)sessionFactory.getCurrentSession().load(Autor.class, id);
	}

	@Override
	public void saveAutor(Autor autor) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().saveOrUpdate(autor);

	}

	@Override
	public void deleteAutor(Autor autor) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().delete(autor);

	}

}
